package gacl.javaweb09.imgVeriFy;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
 * @author gacl
 * 服务器端接收到验证码后的处理
 */
@WebServlet("/servlet/CheckServlet")
public class CheckServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        String clientCheckcode = request.getParameter("validateCode");//接收客户端浏览器提交上来的验证码
        String serverCheckcode = (String) request.getSession().getAttribute("checkcode");//从服务器端的session中取出验证码
        response.setCharacterEncoding("utf-8");
        OutputStream print = response.getOutputStream();
        if (clientCheckcode.equals(serverCheckcode)) {//将客户端验证码和服务器端验证比较，如果相等，则表示验证通过
        	print.write("验证码验证通过！".getBytes());
            System.out.println("验证码验证通过！");
        }else {
        	print.write("验证码验证失败！".getBytes());
            System.out.println("验证码验证失败！");
        }
        response.setHeader("content-type", "text/html;charset=UTF-8");
    }

    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }

}